<?php
header('Content-type:text/html;charset=utf-8');

//开启session
session_start();

//包含数据库配置
include '../public/peizhi.php';

//包含函数
include '../public/func.php';

//调用函数库
$link = db();

//接值
$uname = $_POST['name'];

$pass = md5($_POST['pass']);

//接值验证码
/* $yanzheng = strtolower($_POST['yanzheng']);
$yzm = strtolower($_SESSION['yzm']); */

//判断验证码是否一致
/* if($yanzheng != $yzm){
	exit("<script>alert('验证码错误');window.location.href='./php/denglu.php';</script>");
} */

//准备SQL语句
$sql = "select id,name,pass,pic,qx from user where name='{$uname}' and pass='{$pass}'";

//执行SQL语句
$res = mysqli_query($link,$sql);

//判断执行语句
if($res && mysqli_num_rows($res)){
	$userarr = mysqli_fetch_assoc($res);
	//将数据存到session中,跳转到首页
	$_SESSION['uid'] = $userarr['id'];
	$_SESSION['uname'] = $userarr['name'];
	$_SESSION['pic'] = $userarr['pic'];
	$_SESSION['qx'] = $userarr['qx'];
	echo '<script>alert("用户登录成功");window.location.href="./php/shouye.php";</script>';
	//释放结果
	mysqli_free_result($res);
}else{
	exit('<script>alert("用户名或密码错误");window.location.href="./php/denglu.php";</script>');
}

//关闭数据库连接
mysqli_close($link);




